import { _decorator, Collider2D, Component, Contact2DType, Node } from 'cc';
import { GameManager, GameState } from '../GameManager';
const { ccclass, property } = _decorator;

@ccclass('Bullet_Player_3')
export class Bullet_Player_3 extends Component {

    @property
    moveSpeed:number=600;

    @property
    scSpeed:number=0.1;
    
    bulletCollider: Collider2D = null;

    start() {
        this.bulletCollider=this.node.getComponent(Collider2D);

        this.bulletCollider.on(Contact2DType.BEGIN_CONTACT,()=>{

            // this.bulletCollider.off(Contact2DType.BEGIN_CONTACT);

            // console.log("LASER");
        })

    }

    update(deltaTime: number) {
        this.moving(deltaTime);

        let scY=this.node.getScale().y;
        if(scY<=2){
            scY+=this.scSpeed*deltaTime
        }
        
        this.node.setScale(1,scY);

        if(this.node.position.y>=1200){
            this.node.destroy();
        }
    }

    moving(deltaTime){
        if (GameManager.getInstance().gameState == GameState.START){
                
                const newPos=this.node.getPosition();
                newPos.y+=this.moveSpeed*deltaTime;
                this.node.setPosition(newPos.x,newPos.y);
        }
    }
}


